//
//  ByApiSafety.m
//  chequanbao_ios
//
//  Created by pro on 2017/6/16.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByApiSafety.h"

// model
#import "ByModelSafetyOrder.h"
@implementation ByApiSafety

// 获得保险列表
+ (void)getSafetyList:(ByNetParamsModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure {
    
    
}

// 申请添加车险
+ (void)applyAddCaySafety:(ByNetParamsModel *)model
                  success:(void(^)(ByNetBaseResult *result))success
                  failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Insurance_addApply";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.insurance_id forKey:@"insurance_id"];
    [params setObject:model.name forKey:@"name"];
    [params setObject:model.car_code forKey:@"car_code"];
    [params setObject:model.mobile forKey:@"mobile"];
    [params setObject:model.id_front forKey:@"id_front"];
    [params setObject:model.id_back forKey:@"id_back"];
    [params setObject:model.driving_license_front forKey:@"driving_license_front"];
    [params setObject:model.driving_license_back forKey:@"driving_license_back"];
    [params setObject:model.annual_survey forKey:@"annual_survey"];
    [params setObject:model.three_respons_insurance forKey:@"three_respons_insurance"];
    if (model.his_insurance) {
        [params setObject:model.his_insurance forKey:@"his_insurance"];
    }

    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 添加车险失败: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    
    
}

// 获得保险购买列表
+ (void)getSafetyOrderRecordList:(ByNetParamsModel *)model
                         success:(void(^)(ByNetBaseResult *result))success
                         failure:(void(^)(ByNetBaseResult *result))failure{

    static NSString *apiType = @"By_Insurance_userApplys";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeArray
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           NSMutableArray *temp = [NSMutableArray array];
           for (NSDictionary *dic in responseObject) {
               NSLog(@"%@",dic);
               ByModelSafetyOrder *model = [[ByModelSafetyOrder alloc] initContentWithDic:dic];
               [temp addObject:model];
           }
           result.data = temp;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取保险申请列表: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}

// 上传保险支付截图
+ (void)uploadSafetyCer:(ByNetParamsModel *)model
                success:(void(^)(ByNetBaseResult *result))success
                failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_Insurance_addPayImg";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.insurance_id forKey:@"id"];
    [params setObject:model.img forKey:@"img"];
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = responseObject;
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 上传保险支付截图: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}


// 获得理赔列表
+ (void)getCompensateList:(ByNetParamsModel *)model
                  success:(void(^)(ByNetBaseResult *result))success
                  failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Claim_queryList";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeArray
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取理赔列表: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
    
}

// 查看支付信息
+ (void)lookPayInfo:(ByNetParamsModel *)model
            success:(void(^)(ByNetBaseResult *result))success
            failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_Insurance_getInsuranceOrderInfo";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.insurance_id forKey:@"id"];
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 查看支付信息失败: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

@end
